home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / progut~1 / stdwin.zoo / doc / doc.old next >
Encoding:
Text File  |  1989-10-17  |  44.0 KB  |  1,095 lines

  1. STDWIN -- STANDARD WINDOWS
  2. --------------------------
  3. RATIONALE
  4. ---------
  5.  
  6. STDWIN was born by the desire to make using windows both easier and more
  7. portable for a certain class of applications.  To show why it should be
  8. easier than it currently is, consider for example the calls necessary to
  9. create a window on the Apple Macintosh:
  10.  
  11.     WindowPtr w;
  12.     Rect r;
  13.     
  14.     SetRect(&r, <desired window coordinates>);
  15.     w= NewWindow(
  16.         (Ptr)nil,        /* Optional storage */
  17.         &r,            /* Initial position/size */
  18.         documentProc,        /* Border frame type */
  19.         "Untitled",        /* Title */
  20.         true,            /* Immediately visible */
  21.         0L,            /* Reference constant */
  22.         (WindowPtr)-1        /* Behind no other window */
  23.     );
  24.  
  25. Since I'm doing this without documentation, I may have missed or
  26. reversed some parameters, which shows exactly what I want to illustrate:
  27. the call has too many options, most of which are of no interest to most
  28. application programmers.  Also, it forces the programmer to invent an
  29. initial position for the window, which is often a burden, since this
  30. means one also has to invent a scheme by which to offset the position
  31. for subsequent windows, to avoid creating windows that overlap exactly.
  32.  
  33. What this example doesn't show is the amount of code one has to write
  34. to provide the functionality that Mac users expect from even the
  35. simplest application: windows can be moved, resized, zoomed, closed,
  36. (de)activated, scrolled in two directions, and need to be explicitly
  37. redrawn when they pop up from below another window; none of this is done
  38. automatically by the window manager.  One needs hundreds of lines of
  39. code to provide all this functionality, and most of it has to be
  40. interspersed with application-dependent code (such as to actually draw a
  41. window's contents), which makes it harder to reuse the same code in the
  42. next program one writes.
  43.  
  44. There are other burdens to the application programmer who writes for the
  45. Macintosh, such as the large number of #include files that one must put
  46. in even the simplest programs, and the correspondingly large number of
  47. initialization calls one must make.
  48.  
  49.  
  50. Why using windows should be made more portable is clear if one considers
  51. what is necessary to port a program to a different machine like the
  52. Atari ST, the Commodore Amiga, or a Sun/3 running Suntools or X Windows
  53. (while all these use the same type of processor!).  Not only are the
  54. calls that interface to their window managers different, the semantics
  55. of windows are also subtly different.  Some systems remember a window's
  56. contents when it is covered by another window, so 'update events' are
  57. unheard of; some systems provide a standard interface to scroll bars or
  58. other tools; etc., etc.
  59.  
  60. This seriously limits productivity of application programmers: it can
  61. take many person-months to port a successful program to a new machine,
  62. even though one has used a high-level programming language such as C or
  63. Pascal.  While this effort may be economically justifyable for
  64. bestellers like commercial spreadsheets or wordprocessors, there is a
  65. large class of applications where one can simply not afford these
  66. porting efforts, especially in the academic world, but also for many
  67. specialized applications which aim at a more limited market.
  68.  
  69.  
  70. The current design places an emphasis on full-function windows that give
  71. a scrollable 'view' on some kind of two-dimensional document, e.g. a
  72. program text editor or a graphics design program.  It provides some
  73. tools for simple modal input (e.g., to ask for a string or a file name)
  74. and gives a clean but powerful interface to the common types of pop-up
  75. or pull-down menus (with text items only).  What is clearly missing is a
  76. mechanism to put indicators, icons, controls, rulers, palettes, tool
  77. wells and other gadgets in the window border or on the 'desktop', and
  78. the ability to pop up a collection of gadgets in a dialog window as
  79. commonly seen on the Mac.  Suggestions for a general mechanism here
  80. which fits in STDWIN's philosophy are welcome.  (Are there any other
  81. systems besides the Macintosh and its derivatives like the ST or the
  82. Amige that provide tools for controls and dialogs?)
  83.  
  84. I haven't placed too much emphasis on the design of the graphics
  85. primitives that must be used to draw the contents of a window.  There
  86. are simple routines to draw text strings in a single proportionally
  87. spaced font with a few stylistic variations, and to do simple line
  88. drawings and a few rasterop operations on rectangles.  I plan to extend
  89. the repertoire (and to implement defined functions) as the need arises;
  90. ideally, a standard such as GKS should be adopted, if we want fo
  91. accomodate applications with more drawing requirements.  The is nothing
  92. in the interface definition which precludes color drawing.
  93.  
  94. Although the documentation clearly describes the interface to a library
  95. of C functions, it shouldn't be to hard to translate the interface to
  96. other languages like FORTRAN or Modula.  Ideally, STDWIN should be
  97. defined as a set of 'abstract' functions for which language bindings can
  98. be provided, similarly to the definition of GKS.
  99.  
  100. --- Postscript ---
  101.  
  102. The general aim of STDWIN is to provide high-level features to
  103. applications which can be used with little effort.  Features provided
  104. must be implementable on top of a large number of window managers;
  105. therefore, no precise definitions of some semantical aspects of windows
  106. can be given, in order not to rule out certain implementations (example:
  107. there can be no mention of a 'stack' of windows, since we want to be
  108. compatible with tiling window managers).  This may impair the freedom of
  109. applications, but will enforce a useful standardization of applications
  110. running on a particular system.
  111.  
  112. In many cases STDWIN provides a way to change the default behaviour
  113. if this is considered useful for the application; sometimes such
  114. default-changing routines have an optional or approximate effect,
  115. depending on whether they can be implemented on a particular system.
  116. For best effect this may require some system-dependent tuning when an
  117. application is ported.
  118. DEFINITIONS OF TERMS
  119. --------------------
  120.  
  121. Here are short definitions of many of the terms used in the descriptions
  122. below.  Not all of these definitions are as precise as they could or
  123. should be.  Suggestions for improvement (also about the order of
  124. presentation) are welcome.
  125.  
  126. Window
  127.     A (usually) rectangular area on the screen which contains a view
  128.     on a document.  A window is linked to one particular document;
  129.     it has a title and 'borders', which usually contain scroll bars,
  130.     a grow box and possibly other controls and indicators.  The end
  131.     user may usually change a window's position and size, as well as
  132.     the part of the document onto which the window gives a view.
  133.  
  134. Document
  135.     The (abstract) data structure onto which a window gives a view.
  136.     A document is a rectangular portion of the plane, with maximum h
  137.     and v coordinates which can be set by the application, but it is
  138.     NOT a bitmap: a document may be much larger than the largest
  139.     bitmap that fits in main memory, and it is defined by a 'draw
  140.     procedure'.
  141.  
  142. Window tag
  143.     A small (16-bit) integer used to distinguish windows.  It is set
  144.     by the application.
  145.  
  146. Draw procedure
  147.     The function that defines a document.  When called with the
  148.     coordinates of a rectangle, it should draw (at least) that part
  149.     of the document that lies within this rectangle, using the
  150.     drawing primitives provided by STDWIN, e.g. wdrawline()
  151.     and wdrawtext().
  152.  
  153. Document coordinates
  154.     All coordinates passed to and from STDWIN functions use a
  155.     coordinate system called 'document coordinates'.  These are
  156.     derived through translation from window or screen coordinates:
  157.     the origin of the document is called (0, 0), independent of its
  158.     position on the screen or in the window.  This origin is
  159.     positioned in the UPPER left corner of the document, with the
  160.     positive horizontal (h) axis pointing right and the positive
  161.     vertical (v) axis pointing DOWN.  Document coordinates are
  162.     specified as integers.
  163.  
  164. Pixels
  165.     Are the units of measurement of document (and other)
  166.     coordinates.  The size of a pixel is system-dependent; on most
  167.     screens it is equal to a screen pixel, but on alphanumeric
  168.     displays it equals a character.  There is no guarantee that the
  169.     physical width and height of a pixel are the same; i.e., a
  170.     reactangle with equal width and height measured in pixels need
  171.     not look square on the screen.
  172.     The term pixel is also used to refer to a black or white dot on
  173.     the screen.
  174.  
  175. Text attributes
  176.     The set of parameters that affect the appearance of charactesr
  177.     drawn on the screen with wdrawtext() and friends.  This may
  178.     include font (e.g., Times), stylistic variation (e.g., Italic),
  179.     point size (e.g., 12), and other variations such as underlining
  180.     and inverse video.  The exact set of parameters used is
  181.     system-dependent.  Text attributes are used both by the text
  182.     drawing functions and by the text measuring functions; the
  183.     latter allow an application to calculate the size of a text
  184.     string or paragraph before it is drawn.
  185.  
  186. Text caret
  187.     Each window can have an associated 'text caret'.  This is an
  188.     indicator of where the next character would be inserted.  Its
  189.     appearance is system-dependent; on alphanumeric displays it is
  190.     usually a blinking square or underline positioned at the next
  191.     character position; on bitmapped displays it is usually a
  192.     blinking vertical line just before the next character position.
  193.     There is at most one text caret per window; only the active
  194.     window's caret blinks (or is visible at all).
  195.     (The name 'caret' is used instead of 'cursor' because the latter
  196.     word also refers to the arrow or other symbol moved by the
  197.     mouse.  The name seems to be taken from the symbol actually used
  198.     for its function in Smalltalk-80, which looks like a '^' at the
  199.     baseline pointing at the insert position between two characters.)
  200.  
  201. Event
  202.     Any form of interactive input to the application, reported by
  203.     wgetevent().  Events include keys pressed on the keyboard, menu
  204.     selections, mouse clicks, but also the fact that a new window
  205.     has become 'active'.
  206.  
  207. Active window
  208.     The window to which most events apply.  It is usually displayed
  209.     with a special highlighting of its border or title, and on
  210.     overlapping window systems it is usually the frontmost window,
  211.     and thus visible in its entirety.  At any time there is at most
  212.     one active window.  The application has little or no influence
  213.     over which window is active, since the end user may randomly
  214.     select a window and activate it.  In a multi-programming
  215.     environment, where the screen is shared by several applications,
  216.     at most one application has an active window, and only this
  217.     application will receive keyboard events.
  218. CONVENTIONS
  219. -----------
  220.  
  221. For the benefit of the user of the STWIN library there are some
  222. conventions about naming of functions, parameter order and so on; these
  223. also restrict and guide the design of further additions to the library
  224. (without restricting the expressive power; they are just conventions of
  225. form).
  226.  
  227. - Names of functions, parameters, variables, structure tags and
  228.   structure members are written in lower case.
  229. - Type names and constants are written in UPPER CASE.
  230. - Underscores are not used in names, except in defined constants.
  231.  
  232. - Names of structured types are written in upper case, e.g. WINDOW,
  233.   EVENT.  Such names always denote the struct itself; pointer types are
  234.   made by appending an asterisk, e.g. WINDOW *.
  235. - All functions (except the textedit package) have a name beginning with
  236.   'w'.
  237. - Enquiry functions have a name beginning with 'wget'; corresponding
  238.   changing functions begin with 'wset'.
  239.  
  240. - Standard abbreviations (used in function and parameter names):
  241.   'attr'    attribute
  242.   'bool'    boolean
  243.   'buf'        buffer
  244.   'def'        default
  245.   'doc'        document
  246.   'h'        horizontal
  247.   'len'        length (of a string)
  248.   'pos'        position
  249.   'scr'        screen
  250.   'str'        string
  251.   'v'        vertical
  252.   'win'        window
  253. - When a word has an abbreviation, the abbreviation should be used
  254.   consistently.
  255. - Most other words are written unabbreviated.
  256.  
  257. - Coordinates are given in the order (horizontal, vertical); sizes in
  258.   the order (width, height).  Distances are given as (dh, dv).
  259. - Rectangles are given as (left, top, right, bottom).  The pixels at the
  260.   right and bottom borders are not contained in the rectangle.  I.e.,
  261.   the rectangle (0, 0, 0, 0) contains no pixels; the rectangle
  262.   (0, 0, 1, 1) contains one pixel, at position (0, 0).
  263.  
  264. - When a function has a window pointer as parameter, it is the first
  265.   parameter.
  266. - When a function has a string parameter and a length of the same, the
  267.   length parameter immediately follows the string parameter.  A negative
  268.   length indicates that the string's length is to be computed by
  269.   strlen() (this should work in all such cases).
  270. - When a function has one or more output parameters, these parameters
  271.   (of type 'pointer to ...') have a name beginning with 'p', e.g.
  272.   pwidth, pheight.
  273. - When a function has a struct as parameter, its address is passed,
  274.   even if only its value is used.  [This rule is in part based on the
  275.   old C standard, which has shaped common practice amongst C
  276.   programmers, in part on efficiency considerations.]
  277.  
  278. The textedit package has some private conventions:
  279.  
  280. - All textedit function names start with 'te'.
  281. - The pointer to the TEXTEDIT structure is the first parameter.
  282. DATA STRUCTURES
  283. ---------------
  284.  
  285. The following data structures are defined in <stdwin.h>.
  286.  
  287. WINDOW *
  288.     A pointer to a WINDOW structure, whose contents is
  289.     implementation-defined.  It is used to identify the window that
  290.     an operation applies to.
  291.  
  292. TEXTATTR
  293.     struct textattr {
  294.         ...
  295.     };
  296.     An implementation-defined structure containing all parameters
  297.     to the text drawing and measuring functions.
  298.  
  299. EVENT
  300.     struct event {
  301.         ...
  302.         int type;
  303.         int window;
  304.         union {
  305.             int character;
  306.             int command;
  307.             struct {
  308.                 int h;
  309.                 int v;
  310.                 int clicks;
  311.                 int button;
  312.                 int mask;
  313.             } where;
  314.             struct { int id; int item; } m;
  315.             struct { int left, top, right, bottom; } area;
  316.             ...
  317.         } u;
  318.         ...
  319.     };
  320.     A structure with mostly well-known members (although their
  321.     types may differ slightly, e.g. short or unsigned instead of
  322.     int, and more members may be actually present).  It contains
  323.     information about an `event'.
  324.  
  325. TEXTEDIT
  326.     struct textedit {
  327.         ...
  328.         char *text;
  329.         int foc1, foc2;
  330.         int left, top, right, bottom;
  331.         int nbreaks;
  332.         ...
  333.     };
  334.     A structure with some well-known and some private members.  It
  335.     contains sufficient information for the `textedit' package to do
  336.     simple editing operations on the text.  [Note: the well-known
  337.     members should really be hidden as well, and accessed only
  338.     through access functions!]
  339.  
  340. MENU *
  341.     A pointer to a menu definition.  It is returned by wmenucreate()
  342.     and used to refer to the menu in all further calls that affect a
  343.     particular menu, e.g. wmenuadditem().
  344. LIMITATIONS
  345. -----------
  346.  
  347. - STDWIN library functions don't check their arguments for illegal
  348.   values, such as NULL or invalid window pointers or NULL string
  349.   pointers.  Such parameters are in error and may cause crashes or other
  350.   strange behaviour.  An exception is made for coordinates: these are
  351.   clipped to the valid drawing area, if necessary.
  352. - The STDWIN library makes freely use of statically allocated data; it
  353.   is not reentrant.  Signal handlers should not call longjmp (and
  354.   neither should draw procedures), nor any STDWIN function, when it is
  355.   possible that a STDWIN function is already active.  An exception is
  356.   wdone(), which may be called from a signal handler at any time (even
  357.   before winit() is called or while it is executing), provided no more
  358.   calls to STDWIN follow and the handler termiates the program in some
  359.   way (e.g., by calling exit() or abort()).  (In return, the STDWIN
  360.   library will not call the draw procedure except from wgetevent().)
  361. - Most functions do not report any error condition.  If they can't
  362.   perform their function due to some semantic constraint, they just do
  363.   nothing.  Functions that return pointers will return NULL pointers
  364.   in such cases.  Similar for out-of-memory conditions; these will not
  365.   cause immediate crashes but are not reported back directly either.
  366.   (It will be possible to substitute one's own memory allocator which
  367.   could set an error flag when it detects a memory shortage; there
  368.   should also be a user function to be called whenever an error is
  369.   detected.)
  370. - STDWIN functions may actually be implemented as macros.  It is not
  371.   guaranteed that the arguments are evaluated exactly once!
  372. - The current versions of the library has many external names that
  373.   shouldn't be visible to the application, or at least should start with
  374.   an unlikely combination suchg as '_w_'.  My apologies.  This'll change
  375.   eventually.
  376. USAGE
  377. -----
  378.  
  379. [NOTE: the information in this section is out of date; the versions
  380. described here are ancient!]
  381.  
  382. All definitions for the STDWIN library are contained in the header file
  383. <stdwin.h>.  All routines are to be found in compiled form in the
  384. library file "libstdwin.a".  These reside in system-dependent
  385. directories; you might try the following options to cc (on boring and
  386. tango):
  387.  
  388.     G=~guido
  389.     cc -I$G/include <files> $G/lib/libstdwin.a
  390.  
  391. This gets you the termcap version on boring, but the true windowing
  392. version on tango.
  393. ROUTINES
  394. ========
  395.  
  396. The following routines are available to the application programmer.
  397. Routines marked with [*] are not available in the first
  398. implementation(s).
  399.  
  400.  
  401. INITIALIZATION
  402. --------------
  403.  
  404. void winit();
  405.     Initializes the STDWIN library.  Required before any STDWIN
  406.     calls.  Should be called only once per program run.
  407.  
  408. void wdone();
  409.     Ends use of the STDWIN library.  Removes open windows and resets
  410.     any special system state set by STDWIN.  Required once winit()
  411.     has been called; safe to call before winit() has been called.
  412.  
  413.  
  414. SCREEN PROPERTIES
  415. -----------------
  416.  
  417. void wgetscrsize(int *pwidth, *pheight);            [*]
  418.     Reports the size of the screen in pixels.  This is usually
  419.     larger than the largest window size, since windows have borders.
  420.  
  421. void wgetscrmm(int *pmmhor, *pmmvert);                [*]
  422.     Reports the approximate size of the screen in millimeters.  This
  423.     may be used to scale documents to true life size, or to
  424.     determine the screen's aspect ratio.  Note that this information
  425.     may be unavailable or inaccurate; if unavailable, the size of an
  426.     average monitor is reported.
  427.  
  428.  
  429.  
  430. WINDOW CREATION
  431. ---------------
  432.  
  433. WINDOW *wopen(char *title, void (*drawproc)());
  434.     Opens a window.  Displays the title in the window border.  The
  435.     draw procedure is remembered for later use to process window
  436.     refreshes.  Returns a pointer to the window structure.  The
  437.     window becomes the active window (this will normally cause a
  438.     WE_ACTIVATE event the next time wgetevent() is called).  The
  439.     content area of the window will be redrawn (by calling the draw
  440.     procedure) by a call to wgetevent() in the near future.  The
  441.     window receives the current default text attributes as its
  442.     text attributes.  Passing a NULL pointer as the drawproc changes
  443.     the treatment of window redrawing: whenever part of a window
  444.     must be redrawn, a WE_DRAW event is generated.
  445.  
  446. void wclose(WINDOW *win);
  447.     Disposes of a window and associated data structures.  Some other
  448.     window may become the active window (and a WE_ACTIVATE event is
  449.     then generated).
  450.  
  451. void wupdate(WINDOW *win);
  452.     Causes the window's content area to be redraw (by calling its
  453.     draw procedure) insofar as necessary.  This may be used to show
  454.     changes in a document without calling wgetevent(); it is called
  455.     automatically by wgetevent() for all open windows (with non-NULL
  456.     draw procedures) when that routine finds no other immediate
  457.     events.
  458.  
  459.  
  460. WINDOW DEFAULT PROPERTIES
  461. -------------------------
  462.  
  463. These functions should be called before wopen() if they are to have the
  464. desired effect.  Calling them with specific parameters before each call
  465. to wopen() gives an application precise control over window properties
  466. (if the STDWIN implementation allows it).
  467.  
  468. void wsetdefwinsize(int width, height);                [*]
  469.     Sets the initial size of any windows created subsequently.  This
  470.     request may be ignored or have an approximate effect only,
  471.     depending on the STDWIN implementation.
  472.  
  473. void wsetdefwinpos(int h, v);                    [*]
  474.     Sets the initial position of the top left corner of any
  475.     windows created subsequently (in screen coordinates).  Same
  476.     restrictions as for wsetdefwinsize() above apply.  Moreover,
  477.     the window creation process may try to avoid creating windows
  478.     that overlap completely, by offsetting the default position
  479.     slightly after each window is created.
  480.  
  481. void wsetmaxwinsize(int width, height);                [*]
  482.     Sets the maximum size of any windows created subsequently.  This
  483.     may be important for certain STDWIN implementations where memory
  484.     proportionally to the maximum window size is allocated for a
  485.     window when it is created.  Same restrictions as for
  486.     wsetdefwinsize() above apply.  It is not possible to change a
  487.     window's maximum size once it has been created.  {I wish this
  488.     restriction were not necessary, but the Whitechapel requires
  489.     allocation of a bitmap of the maximum window size when a window
  490.     is created, unless I have overlooked something in the
  491.     documentation.  The screen size is 1K x 1K pixels, which would
  492.     require a 128K bitmap!}
  493.  
  494. [Note: if an implementation has other properties for windows that an
  495. application might want to set a default or a specific value for each
  496. window, there should be similar functions to set such values.
  497. Preferably a standard should emerge for such properties.]
  498.  
  499.  
  500. WINDOW PROPERTIES
  501. -----------------
  502.  
  503. void wsettag(WINDOW *win, short tag);
  504.     Sets a window's 'tag' to the specified value.  This is a field
  505.     that the application can set to any 16-bit value; probably the
  506.     best use one can make of it is to use it as a 'document index'
  507.     so a program with multiple windows can find its own data
  508.     structures belonging to a particular window.  The initial value
  509.     is zero.  Note that it is a 16-bit value to discourage storing a
  510.     pointer in it (which would introduce a serious portability
  511.     problem on machines where pointers are larger than the largest
  512.     size integer).
  513.  
  514. short wgettag(WINDOW *win);
  515.     Returns the window's 'tag', as set by the last call to wsettag()
  516.     for this window.  This is often a macro, so you needn't worry
  517.     about its speed.
  518.  
  519. void wsettitle(WINDOW *win, char *title);
  520.     Displays a new title in the window's border.
  521.  
  522. void wgetwinsize(WINDOW *win, int *pwidth, *pheight);
  523.     Reports the width and height of the window's contents area.
  524.     (that's the part of the document that's visible, not the entire
  525.     document!)
  526.     (Note that most window managers allow the user to resize a
  527.     window, so this information is only valid for a limited time.
  528.     WE_SIZE events make it possible to keep track of a window's size
  529.     changes.)
  530.  
  531. void wgetwinpos(WINDOW *win, int *ph, *pv);            [*]
  532.     Reports the position of the window's upper left corner relative
  533.     to the screen's upper left corner.  Same remarks as wgetwinsize().
  534.  
  535. void wgetwinorigin(WINDOW *win, int *ph, *pv);            [*]
  536.     Reports the position of the window's upper left corner in
  537.     document coordinates [i.e., an indication for the position of
  538.     the scroll bars].  Same remarks as wgetwinsize().
  539.  
  540. [Should there be corresponding functionss wsetwinsize, wsetwinpos etc.?]
  541.  
  542.  
  543. DOCUMENT CONTENTS
  544. -----------------
  545.  
  546. void wsetdocsize(WINDOW *win, int width, height);
  547.     Tells the size of the document; this is needed so that the
  548.     window manager can put up proper scroll bars.  When not set,
  549.     the document size is assumed to be equal to the maximum window
  550.     size.
  551.  
  552. void wchange(WINDOW *win, int left, top, right, bottom);
  553.     Tells the STDWIN library that the indicated rectangle of the
  554.     document needs to be redrawn.  The actual redraw is delayed
  555.     until the first call to wupdate() for the window, or a call to
  556.     wgetevent() that doesn't find a high priority event in its
  557.     queue.
  558.  
  559. void wsetorigin(WINDOW *win, int h, v);                [*]
  560.     Moves the view that the window gives on the document so that the
  561.     point (h, v) is displayed in the upper left corner of the
  562.     window.  (h, v) are clipped to lie within the document.
  563.  
  564. void wshow(WINDOW *win, int left, top, right, bottom);
  565.     Tries to scroll the window to put the given rectangle on the
  566.     screen.
  567.  
  568. void wscroll(WINDOW *win, int left, top, right, bottom, int dh, dv);
  569.     Scrolls the given rectangle by the amount (dh, dv).  No pixels
  570.     outside the rectangle are affected; pixels scrolled out are
  571.     lost, pixels scrolled in are erased.  This may be replaced by a
  572.     call to wshow with the same values for the first 5 parameters.
  573.  
  574.  
  575. TEXT ATTRIBUTES
  576. ---------------
  577.  
  578. [Certain bits of information are repeated here over and over.  How to
  579. avoid this?]
  580.  
  581. void wgetwintextattr(WINDOW *win, TEXTATTR *attr);
  582.     Retrieves the window's text attributes.  There is not much one
  583.     can do with these except pass them to wsetwintextattr() and
  584.     wsettextattr().
  585.  
  586. void wsetwintextattr(WINDOW *win, TEXTATTR *attr);
  587.     Changes the window's text attributes.  A window's text
  588.     attributes are used to initialize the (global) default
  589.     attributes when its draw procedure is called.
  590.  
  591. The following functions have a double meaning: when called from outside
  592. a draw procedure, they affect the global default text attributes; when
  593. used within a draw procedure (when it is called from wgetevent()), they
  594. affect the current text attributes, that are also used by wdrawtext()
  595. and the text measuring functions.  These current text attributes are
  596. initialized to the window's text attributes before the draw procedure
  597. is called; but the window's text attributes are not restored from the
  598. final value of the current text attributes (to change a window's text
  599. attributes, use wsetwintextattr()).
  600.  
  601. To change a window's text attributes, one could do the following
  602. (outside the draw procedure):
  603.  
  604.     TEXTATTR saveattr, winattr;
  605.     wgettextattr(&saveattr);    /* Save current default attrs */
  606.     wgetwintextattr(&winattr);    /* Get window's attrs */
  607.     wsettextattr(&winattr);        /* Use them as new current attrs */
  608.     
  609.     wsetbold();    /* Or whatever; change current attrs here */
  610.     ...
  611.     
  612.     wgettextattr(&winattr);        /* Get changes attrs */
  613.     wsetwintextattr(&winattr);    /* Store them in the window */
  614.     wsettextattr(&saveattr);    /* Restore saved defaults */
  615.  
  616. [Sorry if this looks complicated.  It's easier to change the defaults
  617. before you create the window...]
  618.  
  619. void wsetplain();
  620. void wsetbold();
  621. void wsetitalic();
  622. void wsethilite();
  623. void wsetinverse();
  624. void wsetunderline();
  625.     These functions select the text drawing style.  Setplain()
  626.     resets the style to default; the others (attempt to) select a
  627.     particular alternate style.  At least one alternate style is
  628.     available.  When a particular alternate style is unavailable,
  629.     another alternate style (but not plain) is chosen.  Wsethilite
  630.     chooses an alternate style that is particularly suitable to the
  631.     given screen.
  632.  
  633. void wsetfont(char *font);                    [*]
  634. void wsetpointsize(int size);                    [*]
  635.     [Is this a reasonable interface to select fonts?  E.g.
  636.         wsetfont("times");
  637.         wsetpointsize(12);
  638.     Or is it better to combine the two, e.g.
  639.         wsetfont("times", 12);
  640.     Is there a need for non-integral point sizes?  I've heard about
  641.     phototypesetters that have half-point size increments...]
  642.  
  643. void wgettextattr(TEXTATTR *attr);
  644.     Report the current text attributes.  Thes are the global default
  645.     text attributes when called from outside a draw procedure, the
  646.     current drawing text attributes inside a draw procedure.
  647.  
  648. void wsettextattr(TEXTATTR *attr);
  649.     Set the current text attributes (from a value previously
  650.     retrieved with wgettextattr() or wgetwintextattr()).  Same
  651.     remark as for wgettextattr().
  652.  
  653.  
  654. TEXT MEASURING
  655. --------------
  656.  
  657. The text measuring functions can be used inside or outside a draw
  658. procedure.  Outside, they use the global default text attributes;
  659. inside, they they use the current text attributes (initialized from the
  660. window's text attributes).
  661.  
  662. int wlineheight();
  663.     Returns the height, in pixels, of a text line in the current
  664.     font, style and point size.  This includes the ascent, descent
  665.     and extra line spacing, so that text lines whose baselines or
  666.     top lines differ by this much look 'right' (you may have a
  667.     different opinion, though).
  668.  
  669. int wtextwidth(char *str, int len);
  670.     Returns the width (in pixels) of the string 'str', of length
  671.     'len', when it would be drawn using the current text attributes.
  672.     Note that the width of a string may differ (slightly) from the
  673.     sum of the widths of its characters, due to kerning and other
  674.     magic that goes on during character drawing.  Different selected
  675.     text styles or other attributes also affect the outcome.  It is
  676.     guaranteed, however, that wtextwidth() gives the same result as
  677.     the width reported (implicitly) by wtextdraw() using the same
  678.     text attributes.
  679.  
  680. int wtextbreak(char *str, int len, int width);
  681.     Returns the number of characters string string 'str', of length
  682.     'len', that would fit in 'width' pixels, when drawn with the
  683.     current text attributes.  (This is useful when trying to break
  684.     the lines of a paragraph of text, for instance; this call is
  685.     faster than repeated calls to wtextwidth() until the given width
  686.     is exceeded.)
  687.  
  688.  
  689. THE DRAW PROCEDURE
  690. ------------------
  691.  
  692. The draw procedure that was passed as a parameter to wopen() is called
  693. by wgetevent() when it needs to refresh part of the document.  It should
  694. be declared as follows:
  695.  
  696. void drawproc(WINDOW *win, int left, top, right, bottom);
  697.  
  698. The draw procedure should draw at least that part of the document that
  699. lies within the given rectangle (in document coordinates).  It may draw
  700. more, even all of the document, but this may slow down the drawing
  701. process considerably.  It can use the drawing operations described
  702. below, the text measuring functions and the text attribute functions
  703. described above, and the window and screen property enquiries described
  704. far above.  It should not call any other STDWIN functions.
  705.  
  706.  
  707. DRAWING OPERATIONS
  708. ------------------
  709.  
  710. Note: none of these operations is currently implemented in the termcap
  711. version, and most will probably remain dummies anyway.
  712.  
  713. void wdrawline(int h1, v1, h2, v2);
  714.     Draws a line from (h1, v1) to (h2, v2).  Specifying h1==v1 and
  715.     h2==v2 plots a point.
  716.  
  717. void wdrawbox(int left, top, right, bottom);
  718.     Draws a rectangular box that lies just *inside* the given
  719.     rectangle.  Don't call with left >= right or top >= bottom.
  720.  
  721. void wdrawcircle(int h, v, radius);
  722.     Draws a circle with center (h, v) and given radius.
  723.  
  724. void werase(int left, top, right, bottom);
  725.     Erases the given rectangle.
  726.  
  727. void wpaint(int left, top, right, bottom);
  728.     Paints the given rectangle black.
  729.  
  730. void wshade(int left, top, right, bottom, int percentage);    [*]
  731.     Shades the given rectangle with a colour grey that approximates
  732.     the given percentage; 0 is white, 100 is black.  Unlike
  733.     werase(), wshade() does not clear any pixels, it just adds black
  734.     pixels; so lightly shading an area where a text has already been
  735.     drawn gives the effect of text on a shaded background.  (The
  736.     reverse drawing order also works.)
  737.  
  738. void winvert(int left, top, right, bottom);
  739.     Inverts the pixels in the given rectangle.
  740.  
  741.  
  742. TEXT DRAWING OPERATIONS
  743. -----------------------
  744.  
  745. The following routines may only be used from within a draw procedure
  746. (assuming a draw procedure is only called from wgetevent().
  747.  
  748. int wdrawtext(int h, v, char *str, int len);
  749.     Draws the text string 'str' of length 'len' starting with its
  750.     upper left corner at (h, v).  Returns the h coordinate of the
  751.     upper right corner of the drawn text.  Explanation:
  752.  
  753.     initial (h, v):
  754.     |
  755.     v                                  w
  756.     *-------------------------------------------------------* }   l
  757.     |                            |  }  i
  758.     | #########  #########  #######      #######  #########    |  }  n
  759.     | #          #          #      #    #             #    |   } e
  760.     | #######    #######    #######      ######       #    |    }h
  761.     | #          #          #      #           #      #    |   } e
  762.     | #########  ########   #       #   #######       #    |  }  i
  763.     |                            |  }  g
  764.     *-------------------------------------------------------* }   h
  765.                                 ^     t
  766.                                 |
  767.                 return h coordinate of this point:
  768.  
  769.  
  770. THE TEXT CARET
  771. --------------
  772.  
  773. void wsetcaret(WINDOW *win, int h, v);
  774.     Declares that the window's "text caret" is to be positioned at
  775.     position (h, v).  The caret is placed such that it appears just
  776.     before a character drawn at this position.  Depending on the
  777.     possibilities of the hardware, the caret may blink.  There can
  778.     be at most one text caret per window.
  779.  
  780. void wnocaret(WINDOW *win);
  781.     Removes the window's text caret.
  782.  
  783.  
  784. EVENTS
  785. ------
  786.  
  787. void wgetevent(EVENT *ep);
  788.     Waits until the next event is available, then places
  789.     information about it in the EVENT struct pointed by 'ep' and
  790.     returns.  When no event is available immediately, it redraws
  791.     any windows that still need redrawing (as indicated by a call
  792.     to wchange() or other causes such as windows being moved by the
  793.     user) by calling wupdate() which will call their draw procedure.
  794.     It also handles menu selection, window moving and resizing and
  795.     scrolling.
  796.     
  797.     Event types are the following:
  798.     
  799.     WE_ACTIVATE
  800.         A window becomes active.  The 'window' field of the EVENT
  801.         struct indicates what window.  If this contains NULL, no
  802.         window belonging to the application is active; this is
  803.         possible in multi-process environments.
  804.     
  805.     WE_CHAR
  806.         A character has been typed on the keyboard.  Its ASCII
  807.         value can be found in the field 'u.character'.
  808.     
  809.     WE_COMMAND
  810.         A special command has been issued, usually by pressing a
  811.         special key or clicking some icon.  Codes found in the
  812.         field 'u.command' are:
  813.         
  814.         WC_CLOSE
  815.             Request to close a window.  Which window can be
  816.             found from 'e.window'.
  817.         
  818.         WC_LEFT, WC_RIGHT, WC_UP, WC_DOWN
  819.             Arrow key pressed.
  820.         
  821.         WC_CANCEL, WC_BACKSPACE, WC_TAB, WC_RETURN
  822.             Special key pressed.
  823.         
  824.         There may be other codes depending on the STDWIN
  825.         implementation.
  826.     
  827.     WE_MOUSE_DOWN
  828.         The mouse button was pressed.  The position (expressed
  829.         in document coordinates) can be found in the 'u.where'
  830.         field, subfields 'h' and 'v'.  The 'clicks' subfield
  831.         indicates whether this event is or may be part of a
  832.         multi-click sequence; its value is N if this click is
  833.         the N-th click in a multi-click sequence; N is at least
  834.         1.
  835.     
  836.     WE_MOUSE_MOVE
  837.         The mouse pointer was moved.  This event is only
  838.         reported when the mouse button is down.  The new
  839.         position can be found in the 'u.where' field.  The
  840.         'clicks' subfield is always zero.
  841.     
  842.     WE_MOUSE_UP
  843.         The mouse button was released.  This event is only
  844.         reported when the mouse button was previously down (but
  845.         it is not guaranteed that a WE_MOUSE_UP event will ever
  846.         follow then a WE_MOUSE_DOWN event is reported).  The
  847.         position can be found in the 'u.where' field.  If this
  848.         click was the N-th click in a multi-click sequence, the
  849.         'clicks' field contains N; otherwise it is 0.
  850.     
  851.     WE_MENU
  852.         A menu item was selected.  The menu id and item can be
  853.         found in the fields 'u.m.id' and 'u.m.item'.
  854.     
  855.     WE_SIZE
  856.         A window's size has changed.  The affected window can be
  857.         found in the field 'window'.  The window's new size can
  858.         be requested by calling wgetwinsize().
  859.     
  860.     A STDWIN application may define more events with an
  861.     implementation-dependent meaning.  It may also define additional
  862.     implementation-dependent fields in the EVENT struct.  Most
  863.     applications should refrain from using these.
  864.  
  865.  
  866. MENUS
  867. -----
  868.  
  869. There are two kinds of menus: 'global' and 'local' menus.  Global menus
  870. are available independent of which window is active; local menus must
  871. explicitly be attached to one or more windows, and are only available if
  872. they have been attached to the currently active window.  By default, all
  873. windows created are global; this can be changed by calling
  874. wmenusetdeflocal(TRUE).  Most systems have fairly low limits on the
  875. number and size of menus; 5 to 10 menus of 10 to 20 items can usually
  876. be accomodated.
  877.  
  878. MENU *wmenucreate(int id, char *title);
  879.     Creates a new menu with the given menu id and title.  The id is
  880.     used to report menu selection events for this menu, see
  881.     wgetevent() above, subsection WE_MENU.  The id should be in the
  882.     range [1..255], and differ from all other menu ids in use.
  883.     Initially, the menu contains no items.  It returns a pointer to
  884.     the menu definition, which should be used in all subsequent
  885.     calls that affect this menu; a NULL pointer is returned if the
  886.     menu couldn't be created.
  887.  
  888. int wmenuadditem(MENU *menu, char *text, int shortcut);
  889.     Adds an item to the menu.  The item's item number is one
  890.     higher than the highest item already in the menu; the first
  891.     item gets number zero.  This item number is the return
  892.     value.  Some systems interpret various punctuation characters
  893.     in the text as special flags, so it is best to limit the
  894.     text to alphanumeric characters and space.  The item may
  895.     have a keyboard shortcut; shortcuts are usually implemented
  896.     by using an extra shift modifier ('ALT' or 'META' key) or
  897.     a prefix such as 'ESC'.  If no shortcut is desired, -1
  898.     should be passed for this parameter, otherwise a positive
  899.     ASCII code should be passed.
  900.     Items cannot be removed or reordered from a menu, nor can their
  901.     shortcuts be changed; an item's text chan be changed, see
  902.     below.
  903.     Adding an empty string to a menu creates an empty, unselectable
  904.     item, which may serve to separate groups of items in a long
  905.     menu.
  906.  
  907. void wmenusetitem(MENU *menu, int item, char *text);
  908.     Changes the text of the item to the new text.  The parameter
  909.     'item' must be the item number of an existing item in the menu.
  910.     A conventional way to temporarily disable a menu item is to set
  911.     its text to the empty string; it can be enabled again by
  912.     setting the text back to what it originally was.
  913.  
  914. void wmenudelete(MENU *menu);
  915.     Deletes the menu.  If it is a local menu, it is detached from
  916.     all windows to which it was attached.  All storage associated
  917.     with the menu is released.
  918.  
  919. void wmenuattach(WINDOW *win, MENU *menu);
  920.     Attaches a local menu to a given window.  This makes the menu
  921.     available whenever the window is active.  A menu may be attached
  922.     to as many windows as desired.  Don't use this for global menus.
  923.  
  924. void wmenudetach(WINDOW *win, MENU *menu);
  925.     Detaches a local menu from a given window.  No effect for global
  926.     menus.
  927.  
  928. void wmenusetdeflocal(bool local);
  929.     Sets the default status for subsequently created menus.
  930.     Initially, all menus created will be global.
  931.  
  932.  
  933. DIALOG TOOLS
  934. ------------
  935.  
  936. The following fuctions are available for simple dialogs that ask a
  937. yes/no question or request a file name, and a few more.
  938.  
  939. void wmessage(char *str);
  940.     Puts up an error message.  This may be put in a separate box in
  941.     front of all other windows and require some user action before
  942.     it goes away; or it may be placed in a less conspicuous position
  943.     but stay there for a while.  When a second message is issued,
  944.     the first is generally overwritten.
  945.  
  946. bool waskstr(char *prompt, char *buf, int buflen);
  947.     Asks the user to type a text string.  The string is placed in
  948.     buffer 'buf' of length 'buflen'; 'buf' is guaranteed to be
  949.     zero-terminated.  The initial content of 'buf' is used as a
  950.     default reply.  The user has the possibility to cancel the
  951.     interaction, in which case the function returns FALSE (and buf
  952.     is left undefined).
  953.     
  954.     Cancellation is implemented in a system-dependent manner; if a
  955.     system has a conventional 'interrupt' key or key combination,
  956.     this is generally used.  On Unix systems the interrupt character
  957.     as set by 'stty' is used.
  958.     
  959.     [*] Current implementations ignore the given buffer length.  The
  960.     buffer should be at least 256 bytes long.
  961.  
  962. int waskync(char *question, int def);
  963.     Asks a question to which a yes/no answer is applicable.  The
  964.     user may also cancel the interaction.  Return values are: 1 for
  965.     yes, 0 for no, -1 for cancelled.  The parameter 'def' is the
  966.     default reply (chosen when the users presses return without
  967.     typing anything) and should also be one of -1, 0 or 1, with the
  968.     same meaning.
  969.  
  970. bool waskfile(char *prompt, char *buf, int buflen, bool new);
  971.     Asks for a file name.  The file name is returned into buffer
  972.     'buf' of length 'buflen' (which is zero-terminated).  The
  973.     initial content of 'buf' is used as a default file name.  The
  974.     'new' parameter determines checks made on the file: when FALSE,
  975.     the file must exist and be readable; when TRUE, the file must
  976.     not exist but should be creatable, or it must be readable (and
  977.     if it exists, the user is asked for confirmation to overwrite
  978.     it).  It is not guaranteed but very probable that a subsequent
  979.     fopen() of the file will succeed.  If the user cancels the
  980.     interaction, the function returns FALSE and the content of 'buf'
  981.     is undefined.
  982.  
  983. void wperror(char *name);
  984.     Shows an I/O error message based on the current value of
  985.     'errno' and the string 'name', possibly like the corresponding
  986.     Unix function: "name: <cryptic error message>".  The message is
  987.     put out in a similar style as messages put out by wmessage().
  988.  
  989.  
  990. TEXTEDIT TOOLS
  991. --------------
  992.  
  993. These allow small sections of text (usually one or a few lines or
  994. paragraphs only) to be manipulated in a standard way.  The text has a
  995. 'focus', which is used like the Macintosh text focus.  All routines that
  996. change the text make appropriate calls to wchange(); for these to be
  997. effectuated the draw procedure should call tedraw() for each text edit
  998. struct that belongs to a given window.
  999.  
  1000. TEXTEDIT *tealloc(WINDOW *win, int h, v, width);
  1001.     Allocates an empty text edit structure in the given window or
  1002.     width 'width' with its upper left corner at (h, v).  It is set
  1003.     up to use the window's current text attributes.  If allocation
  1004.     fails, it returns a NULL pointer.
  1005.  
  1006. void tefree(TEXTEDIT *te);
  1007.     Deallocates the given textedit structure.
  1008.  
  1009. void tesetfocus(TEXTEDIT *te, int foc1, foc2);
  1010.     Sets the 'focus' from the position before character 'foc1' to
  1011.     the position before character 'foc2'.  I.e., if foc1==foc2, the
  1012.     focus contains no characters but is an 'insert focus'.  If foc2
  1013.     is larger than the number of characters in the text, it is set
  1014.     to the end of the text.
  1015.  
  1016. void tereplace(TEXTEDIT *te, char *str);
  1017.     Replaces the characters from foc1 to foc2-1 in the text by the
  1018.     contents of string 'str'.  The new focus is set after the last
  1019.     character of the inserted string.  This is effectively a delete
  1020.     of 'str' is empty, or an insert if the focus is an insert focus.
  1021.  
  1022. void tebackspace(TEXTEDIT *te);
  1023.     Deletes the focus when it contains at least a character;
  1024.     otherwise, deletes the character before the focus, if any.  The
  1025.     new focus is an insert position at the first deleted character.
  1026.  
  1027. bool teclick(TEXTEDIT *te, int h, v);
  1028.     Places the focus at the text position corresponding to the point
  1029.     (h, v).  Returns FALSE if (h, v) is outside the text's
  1030.     rectangle, and then the focus is unchanged (but a position
  1031.     beyond the end of the last line selects an insert focus at the
  1032.     end of the text).
  1033.  
  1034. void tearrow(TEXTEDIT *te, int code);
  1035.     Performs the effect of an arrow key on the focus.  In 'code' the
  1036.     code of an arrow key should be given as reported by wgetevent()
  1037.     (subsection WE_COMMAND).
  1038.  
  1039. bool teevent(TEXTEDIT *te, EVENT *ep);
  1040.     If the event is applicable to the textedit record, executes it
  1041.     and returns TRUE, otherwise returns FALSE.  Applicable events
  1042.     are (at least): WE_MOUSE_DOWN, WE_CHAR, and WE_COMMAND with
  1043.     command codes for arrows, WC_BACKSPACE and WC_RETURN.  After a
  1044.     WE_MOUSE_DOWN event, this may eat subsequent WE_MOUSE_MOVE and
  1045.     a WE_MOUSE_UP event.
  1046.  
  1047. void tedraw(TEXTEDIT *te);
  1048.     Should be called only in a draw procedure, to draw the entire
  1049.     text rectangle.
  1050.  
  1051. char *tegettext(TEXTEDIT *te);
  1052.     Returns a pointer to the entire text contained in the textedit
  1053.     struct.  This should only be used to make a copy of the text;
  1054.     the text may float around in memory.
  1055.  
  1056. char *tegetselection(te);                    [*]
  1057.     Returns a pointer to a copy of the text contained in the text
  1058.     selection.  This pointer points to memory that has been
  1059.     allocated with malloc() and should eventually be freed by the
  1060.     caller with free().
  1061.  
  1062. void temove(TEXTEDIT *te, int h, v, width);
  1063.     Moves the textedit struct to a new place in the document.  The
  1064.     point (h, v) is the new top left corner, while 'width' is the
  1065.     new width.
  1066.  
  1067. int tegetnlines(TEXTEDIT *te);
  1068.     Returns the number of lines contained in the textedit struct.
  1069.     This includes any line breaks inserted to make the text fit in
  1070.     the given width.
  1071.  
  1072. int tegetfoc1(TEXTEDIT *te);
  1073. int tegetfoc2(TEXTEDIT *te);
  1074.     These return the beginning and end of the text focus, as set by
  1075.     tesetfocus() or other calls.
  1076.  
  1077. int tegetleft(TEXTEDIT *te);
  1078. int tegettop(TEXTEDIT *te);
  1079. int tegetright(TEXTEDIT *te);
  1080. int tegetbottom(TEXTEDIT *te);
  1081.     These return the coodinates of the four courners of the
  1082.     rectangle in which the text is being displayed.
  1083.  
  1084. int wdrawpar(int h, v, char *text, int width);
  1085.     Draws a paragraph of text in a rectangle with (h, v) as its top
  1086.     left corner which is 'width' wide; it is drawn exactly the same
  1087.     as when the text would have been put in a textedit struct at the
  1088.     same position.  It returns the v coordinate of the bottom of the
  1089.     box in which the text is drawn.
  1090.  
  1091. int wparheight(char *text, int width);
  1092.     Returns the height of a paragraph of text (in document
  1093.     coordinates) when it would be drawn by wdrawpar using the same
  1094.     width.
  1095.